package com.dearbinge.data.service.impl.moneyDetail;

import com.baomidou.mybatisplus.plugins.Page;
import com.dearbinge.data.api.moneyDetail.MoneyDetailService;
import com.dearbinge.data.dao.MoneyDetailMapper;
import com.dearbinge.data.pojo.moneyDetail.MoneyDetail;
import com.dearbinge.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "moneyDetailService")
public class MoneyDetailServiceImpl implements MoneyDetailService {

    @Autowired
    private MoneyDetailMapper moneyDetailMapper;

    @Override
    public Integer update(MoneyDetail moneyDetail) {
        Integer dataCode = moneyDetailMapper.update(moneyDetail);
        return dataCode;
    }

    @Override
    public Integer insert(MoneyDetail moneyDetail) {
        Integer dataCode = moneyDetailMapper.insert(moneyDetail);
        return dataCode;
    }

    @Override
    public Integer delete(Integer id) {
        Integer dataCode = moneyDetailMapper.delete(id);
        return dataCode;
    }

    @Override
    public Page getByPage(String userId, Integer pageNo, Integer pageSize, Integer isDeleted) {
        pageNo = PageUtils.getDefaultValues(pageNo, 1);
        pageSize = PageUtils.getDefaultValues(pageSize, 10);
        isDeleted = (null == isDeleted  ? 0 : isDeleted);
        Page<MoneyDetail> page = new Page<>(pageNo,pageSize);
        Integer count = moneyDetailMapper.count(userId,isDeleted);
        page.setTotal(count);
        List<MoneyDetail> list = moneyDetailMapper.getByPage(userId,isDeleted,page);
        page.setRecords(list);
        return page;
    }
}
